package com.xzr.anno;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * @Author：jojo
 * @Date：2022/1/20 17:14
 * @Description :TODO
 */
@Aspect      // 表示该类为一个切面
@Component    //表示该类为spring的一个组件
public class MyAnnoAsperctJ {

    @Pointcut("execution(* com.xzr.service.*.*(..))")
    private void myPointCut(){}

    @Before("myPointCut()")
    public void myBefore(JoinPoint joinPoint){
        System.out.println("前置通知执行了");
    }
    @AfterReturning("myPointCut()")
    public void myAfterReturning(JoinPoint joinPoint){
        System.out.println("后置通知执行了");
    }

    @Around("myPointCut()")
    public Object myAround(ProceedingJoinPoint proceedingJoinPoint) throws Throwable{
        System.out.println("环绕通知执行了");
        Object proceed = proceedingJoinPoint.proceed();
        System.out.println("环绕通知结束");
        return proceed;
    }
    @AfterThrowing(value = "myPointCut()",throwing = "e")
    public void myAfterThrowing(JoinPoint joinPoint,Throwable e){
        System.out.println("异常通知");
        System.out.println("报错信息" + e.getMessage());
    }

    @After("myPointCut()")
    public void myAfter(){
        System.out.println("最终通知   不管怎样都会执行");
    }
}
